package com.ruoyi.bantong.controller;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bantong.domain.BtRedbagPollDetails;
import com.ruoyi.bantong.service.IBtRedbagPollDetailsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 红包玩法详情Controller
 * 
 * @author laohei
 * @date 2021-02-06
 */
@RestController
@RequestMapping("/bantong/redbagdetails")
public class BtRedbagPollDetailsController extends BaseController
{
    @Autowired
    private IBtRedbagPollDetailsService btRedbagPollDetailsService;

    /**
     * 查询红包玩法详情列表
     */
    //@PreAuthorize("@ss.hasPermi('bantong:details:list')")
    @GetMapping("/list")
    public TableDataInfo list(BtRedbagPollDetails btRedbagPollDetails)
    {
        startPage();
        List<BtRedbagPollDetails> list = btRedbagPollDetailsService.selectBtRedbagPollDetailsList(btRedbagPollDetails);
        return getDataTable(list);
    }

    /**
     * 查询红包玩法 中奖记录 前台使用
     */
    //@PreAuthorize("@ss.hasPermi('bantong:details:list')")
    @GetMapping("/playList")
    public TableDataInfo selectBtRedbagWinList(BtRedbagPollDetails btRedbagPollDetails)
    {
        btRedbagPollDetails.setUserId(SecurityUtils.getBtUserId());
        startPage();
        List<Map<String,Object>> list = btRedbagPollDetailsService.selectBtRedbagWinList(btRedbagPollDetails);
        return getDataTable(list);
    }

    /**
     * 导出红包玩法详情列表
     */
    //@PreAuthorize("@ss.hasPermi('bantong:details:export')")
    @Log(title = "红包玩法详情", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BtRedbagPollDetails btRedbagPollDetails)
    {
        List<BtRedbagPollDetails> list = btRedbagPollDetailsService.selectBtRedbagPollDetailsList(btRedbagPollDetails);
        ExcelUtil<BtRedbagPollDetails> util = new ExcelUtil<BtRedbagPollDetails>(BtRedbagPollDetails.class);
        return util.exportExcel(list, "details");
    }

    /**
     * 获取红包玩法详情详细信息
     */
    //@PreAuthorize("@ss.hasPermi('bantong:details:query')")
    @GetMapping(value = "/{rpdId}")
    public AjaxResult getInfo(@PathVariable("rpdId") Integer rpdId)
    {
        return AjaxResult.success(btRedbagPollDetailsService.selectBtRedbagPollDetailsById(rpdId));
    }

    /**
     * 新增红包玩法详情
     */
    //@PreAuthorize("@ss.hasPermi('bantong:details:add')")
    @Log(title = "红包玩法详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BtRedbagPollDetails btRedbagPollDetails)
    {
        return toAjax(btRedbagPollDetailsService.insertBtRedbagPollDetails(btRedbagPollDetails));
    }

    /**
     * 修改红包玩法详情
     */
    //@PreAuthorize("@ss.hasPermi('bantong:details:edit')")
    @Log(title = "红包玩法详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BtRedbagPollDetails btRedbagPollDetails)
    {
        return toAjax(btRedbagPollDetailsService.updateBtRedbagPollDetails(btRedbagPollDetails));
    }

    /**
     * 删除红包玩法详情
     */
    //@PreAuthorize("@ss.hasPermi('bantong:details:remove')")
    @Log(title = "红包玩法详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rpdIds}")
    public AjaxResult remove(@PathVariable Integer[] rpdIds)
    {
        return toAjax(btRedbagPollDetailsService.deleteBtRedbagPollDetailsByIds(rpdIds));
    }
}
